package br.com.eSink.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class ConnectionDatabase {

    public Connection con;

    public ConnectionDatabase() {
    }

    public Connection openConnection(String url, String user, String pass) throws SQLException {
        try {
            Class.forName("org.hsqldb.jdbcDriver");
            con = DriverManager.getConnection("jdbc:hsqldb:file:" + url, user, pass);
            System.out.println("Conectou ao banco de dados com url " + url + " e usuário " + user + " com sucesso!");
        } catch (ClassNotFoundException | SQLException e) {
            System.out.println("Erro na conexão. " + e);
            System.exit(0);
        }
        return con;
    }

    public void closeConnection(Connection con) throws SQLException {
        try {
            con.close();
            System.out.println("Desconectou do banco de dados!");
        } catch (Exception e) {
            System.out.println("Erro na desconexão. " + e);
        }
    }
}
